<?php
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])){
	header($_SERVER['HTTP_HOST']);
	exit();
}

$imgId = array();
foreach($this->imageGroup as $k => $v){	
	array_push($imgId, $v->ID);
}

$all_att = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE (post_mime_type = 'image/png' or post_mime_type = 'image/jpeg' or post_mime_type = 'image/gif') and post_type = 'attachment' and ID not in (".join(',',$imgId).")");
?>
<div id="px_message"></div>

<div class="wrap">
	<h2><?php _e("PhotoXhibit Albums Images", 'photoxhibit'); ?></h2>
	<div class="metabox-holder" id="poststuff">
    	<div id="side-info-column" class="inner-sidebar">
        
            <div class="meta-box-sortables" id="side-sortables" style="position: relative;">
                <div class="postbox" id="submitdiv">
                    <h3 class="hndle"><span>Upload</span></h3>
                    <div class="inside">
                    	<form id="form1" action="<?php echo $this->pluginUrl;?>upload&amp;aid=<?php echo $_GET['aid'];?>" method="post" enctype="multipart/form-data">
                        	<input type="hidden" name="aid" id="aid" value="<?php echo $_GET['aid'];?>"/>
                        
                            <fieldset class="misc-pub-section">
                                <div id="divSWFUploadUI">
                                    <div class="fieldset  flash" id="fsUploadProgress">
                                        <span class="legend">Upload Queue</span>
                                    </div>
                                    <p id="divStatus">0 Files Uploaded</p>
                                </div>
                                
                                <noscript style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px;">
                                    We're sorry.  SWFUpload could not load.  You must have JavaScript enabled to enjoy SWFUpload.                               <label><?php _e('Multiple Photo Upload', 'photoxhibit'); ?></label>
                                <input type="file" class="Filedata" name="Filedata[]" /> <br/>
                                </noscript>
                                <div id="divLoadingContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
                                    SWFUpload is loading. Please wait a moment...
                                </div>
                                <div id="divLongLoading" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
                                    SWFUpload is taking a long time to load or the load has failed.  Please make sure that the Flash Plugin is enabled and that a working version of the Adobe Flash Player is installed.
                                </div>
                                <div id="divAlternateContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
                                    We're sorry.  SWFUpload could not load.  You may need to install or upgrade Flash Player.
                                    Visit the <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Adobe website</a> to get the Flash Player.
                                </div>

                            </fieldset>
                            <div id="major-publishing-actions">
                                <div id="publishing-action">
                                	<input id="btnCancel" class="button-primary" type="button" value="Cancel All Uploads" disabled="disabled" />
                                	<span id="spanButtonPlaceholder"></span>
	                                <input type="submit" value="Upload" 
                                    	accesskey="p" tabindex="5" 
                                        id="btnUpload"
                                        class="button-primary" name="publish"/>
                                </div>
                                <div class="clear"/>
                            </div>
                        </form>
                    </div>
                </div>
	            <!-- end: postbox -->

            </div>
            <!-- end: side-sortables -->
        

			<div class="meta-box-sortables">
                <div class="postbox">
                    <h3 class="hndle"><span>Images not in Album</span></h3>
                    <div class="inside clearfix" id="otherAttachments">
<?php
foreach($all_att as $img):
    if ( $_tags = get_the_tags($img->ID) ) {
        foreach ( $_tags as $tag )
            $tags[] = $tag->name;
        $tags = attribute_escape(join(', ', $tags));
    }
	echo '<div id="img_'.$img->ID.'" img="'.$img->ID.'" class="otherAttachments">';
		echo '<span class="cb"><input type="checkbox" name="newimages[]" value="'.$img->ID.'"/></span>';
		$src = wp_get_attachment_image_src($img->ID);
		echo '<span class="img"><img src="'.$src[0].'" class="attachment-80x60" height="60" width="60"/></span>';
		
		echo '<input type="hidden" name="ID" value="';
		echo $img->ID . '"/>';
		
		echo '<input type="hidden" name="post_name" value="';
		echo $img->post_name . '"/>';
		echo '<input type="hidden" name="post_title" value="';
		echo $img->post_title . '"/>';
		echo '<input type="hidden" name="post_path" value="';
		echo $src[0] . '"/>';
		echo '<input type="hidden" name="tags" value="'.$tags.'"/>';
		echo '<textarea style="position:absolute;left:-999em;top:-999em;" cols="1" rows="1" name="post_content">';
		echo $img->post_content . '</textarea>';
		
	echo '</div>';
endforeach;
?>
                    </div>
                    <div class="formSubmit">
                        <div class="submit">
                            <input type="submit" value="Add Images" 
                                accesskey="p" tabindex="5" 
                                id="btnAddImages"
                                class="button-primary" name="add_images"/>
                        </div>
                    </div>
                </div>
	            <!-- end: postbox -->
            </div>
			<!-- end: meta-box-sortables -->

        </div>
        <!-- end: inner-sidebar -->
        
    </div>
    
    <div id="post-body" class="has-sidebar">
    	<div id="post-body-content" class="has-sidebar-content">
            <div class="postbox" id="submitdiv">
                <h3 class="hndle"><span>Album Images</span></h3>
                <div class="inside">
    
            <table cellpadding="0" cellspacing="0" border="0" id="imageTable"><tbody>
<?php
if( count($this->imageGroup) > 0 ){
	$cnt = 0;
foreach($this->imageGroup as $k => $v){
    $src = wp_get_attachment_image_src($v->ID);
    if ( $_tags = get_the_tags($v->ID) ) {
        foreach ( $_tags as $tag )
            $tags[] = $tag->name;
        $tags = attribute_escape(join(', ', $tags));
    }
	
	if( $cnt++ % 2 == 0 ){
		$cls = 'beven';
	}
	else{
		$cls = '';
	}
?><tr><td class="<?php echo $cls;?>">
<input type="hidden" name="post_name" id="<?php echo $v->albumPhotos_id;?>post_name" value="<?php echo $v->post_name;?>"/>
<input type="hidden" name="post_title" id="<?php echo $v->albumPhotos_id;?>post_title" value="<?php echo (empty($v->post_title)) ? '' : $v->post_title;?>"/>
<input type="hidden" name="tags" id="<?php echo $v->albumPhotos_id;?>tags" value="<?php echo (empty($tags)) ? '' : $tags;?>"/>
<input type="hidden" name="isactive" id="<?php echo $v->albumPhotos_id;?>isactive" value="<?php echo ($v->albumPhotos_isactive == '1') ? '1' : '0';?>"/>
<textarea style="position:absolute;left:-999em;top:-999em;" cols="1" rows="1" name="post_content" id="<?php echo $v->albumPhotos_id;?>post_content"/><?php echo (empty($v->post_content)) ? '' : $v->post_content;?></textarea>

            <table cellpadding="0" cellspacing="0" border="0" imageid="<?php echo $v->albumPhotos_id;?>">
                <tr>
                    <td rowspan="5" align="left" valign="top" width="105" style="width:105; overflow:auto;">
                        <img class="attachment-80x60" width="100" src="<?php echo $src[0];?>"/>
                    </td>
                    <td><?php _e('Image Name:', 'photoxhibit'); ?> <?php echo $v->post_name;?></td>
                </tr>
                <tr>
                    <td><?php _e('Image Alt/Title:', 'photoxhibit'); ?>  <?php echo (empty($v->post_title)) ? 'None Yet' : $v->post_title;?></td>
                </tr>
                <tr>
                    <td><?php _e('Image Tags:', 'photoxhibit'); ?>  <?php echo (empty($tags)) ? 'None Yet' : $tags;?></td>
                </tr>
                <tr>
                    <td><?php _e('Is Active:', 'photoxhibit'); ?> <?php echo ($v->albumPhotos_isactive == '1') ? 'true' : 'false';?></td>
                </tr>
                <tr>
                    <td><?php _e('Description:', 'photoxhibit'); ?>  <?php echo (empty($v->post_content)) ? 'None Yet' : $v->post_content;?></td>
                </tr>
                <tr>
                    <td colspan="2" style="height:15px;" align="right">
                        [<a href="<?php echo $this->pluginUrl;?>delete_image&amp;iid=<?php echo $v->albumPhotos_id;?>" imageid="<?php echo $v->albumPhotos_id;?>" class="deleteImageLink"><?php _e('Delete Image', 'photoxhibit'); ?></a>]
                        |
                        <a href="#" class="editTextLink"><?php _e('Edit text', 'photoxhibit'); ?></a>
                        <!--
                        |
                        <a href="admin.php?page=px_manageAlbum&amp;action=edit_image&amp;aid=<?php echo $_GET['aid'];?>&amp;iid=<?php echo $v->albumPhotos_id;?>" class="editImageLink"><?php _e('Edit Image', 'photoxhibit'); ?></a>
                        -->
                    </td>
                </tr>
            </table>
	</td></tr>
<?php
}//
}
else{
echo '<tr><td>';
_e('No images for this album yet', 'photoxhibit');
echo '</td></tr>';
}
?>
            </tbody></table>
            </div>
    	</div>
    </div>
    <!-- end: has-sidebar -->
</div>